Conditions | 1 |
Paths | 1 |
Total Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
13 | describe('GraphQL Brewery (queries)', function() { |
||
14 | |||
15 | beforeEach(function(done){ |
||
16 | BreweryData.forEach(function (aBeer) { |
||
17 | var newBrewery = new Brewery(aBeer); |
||
18 | newBrewery.save(); |
||
19 | }); |
||
20 | BeerData.forEach(function (aBeer) { |
||
21 | var newBeer = new Beer(aBeer); |
||
22 | newBeer.save(); |
||
23 | }); |
||
24 | done(); |
||
25 | }); |
||
26 | |||
27 | afterEach(function(done){ |
||
28 | Beer.collection.drop(); |
||
29 | Brewery.collection.drop(); |
||
30 | done(); |
||
31 | }); |
||
32 | |||
33 | it('should display all the breweries', function(done) { |
||
34 | var graphqlQuery = ` |
||
35 | { |
||
36 | breweries { |
||
37 | name |
||
38 | location |
||
39 | } |
||
40 | } |
||
41 | `; |
||
42 | |||
43 | chai.request(server) |
||
44 | .post('/graphql') |
||
45 | .send({query: graphqlQuery}) |
||
46 | .end(function(err, res){ |
||
47 | res.should.have.status(200); |
||
48 | res.should.be.a.json; |
||
|
|||
49 | res.body['data']['breweries'].should.be.an('array'); |
||
50 | res.body['data']['breweries'][0].should.have.property('name'); |
||
51 | res.body['data']['breweries'][0].should.have.property('location'); |
||
52 | done(); |
||
53 | }); |
||
54 | }); |
||
55 | |||
56 | it('should display a SINGLE brewery', function(done) { |
||
57 | var newBrewery = new Brewery({ |
||
58 | _id: 'test_brewery', |
||
59 | name: 'Test Brewery', |
||
60 | location: 'Beerland' |
||
61 | }); |
||
62 | |||
63 | newBrewery.save(function(err, data) { |
||
64 | |||
65 | var graphqlQuery = ` |
||
66 | { |
||
67 | brewery(id: "${data._id}") { |
||
68 | name |
||
69 | location |
||
70 | } |
||
71 | }`; |
||
72 | |||
73 | chai.request(server) |
||
74 | .post('/graphql') |
||
75 | .send({query: graphqlQuery}) |
||
76 | .end(function(err, res){ |
||
77 | res.should.have.status(200); |
||
78 | res.should.be.a.json; |
||
79 | res.body.should.be.an('object'); |
||
80 | res.body['data']['brewery']['name'].should.equal('Test Brewery'); |
||
81 | res.body['data']['brewery']['location'].should.equal('Beerland'); |
||
82 | done(); |
||
83 | }); |
||
84 | }); |
||
85 | }); |
||
86 | }); |
||
87 |